import json
import os


class ConfigFile:
    threads = 1,
    inputPath = "./input"
    outputPath = "./output"
    delConfirm = True
    fps = 25
    videoCodec = "libx264"
    audioCodec = "aac"
    videoType = [".mp4", ".avi"]
    imageType = [".jpg", ".png"]
    audioType = [".wav", ".acc", ".m4a", ".mp3"]
    subClip = True
    subClipStart = 2
    subClipEnd = 2
    setLogoClip = False
    logoClipType = "image"
    logoClipPath = "./media/logo.png"
    logoClipWidth = 0
    logoClipHeight = 0
    logoClipPosX = 20
    logoClipPosY = 20
    setStartClip = False
    startClipType = "image"
    startClipDuration = 2
    startClipPath = "./media/start.png"
    setEndClip = False
    endClipType = "image"
    endClipDuration = 2
    endClipPath = "./media/end.png"

    def __init__(self):
        self._loadConfig()

    def _loadConfig(self, path="./config.json"):
        if os.path.exists(path):
            with open(path, "r", encoding="utf-8") as f:
                data = json.loads(f.read())
                for key, val in data.items():
                    if hasattr(self, key):
                        self.__setattr__(key, val)
        if not os.path.exists(self.inputPath):
            os.mkdir(self.inputPath)
        if not os.path.exists(self.outputPath):
            os.mkdir(self.outputPath)

    def reloadConfig(self):
        self._loadConfig()

    def initConfig(self, path="./config.json"):
        data = {
            "delConfirm": True,
            "subClip": True,
            "subClipStart": 2,
            "subClipEnd": 2,
            "setLogoClip": False,
            "logoClipType": "image",
            "logoClipPath": "./media/logo.png",
            "logoClipWidth": 0,
            "logoClipHeight": 0,
            "logoClipPosX": 20,
            "logoClipPosY": 20,
            "setStartClip": False,
            "startClipType": "image",
            "startClipDuration": 2,
            "startClipPath": "./media/start.png",
            "setEndClip": False,
            "endClipType": "image",
            "endClipDuration": 2,
            "endClipPath": "./media/end.png",
        }
        with open(path, "w", encoding="utf-8") as f:
            f.write(json.dumps(data, indent=2))


Config = ConfigFile()